import Vue from 'vue';

const state = {
  filter:{
      rows: 10,
      page: 1,
      total: 0,
  },
  newsCate:"",
};

const getters = {
  getFilterNews:state => {
    return state.filter;
  },
  getNewsCate:state => {
    return state.newsCate;
  }
};

const mutations = {
  setFilter:(state,payload) => {
    state.filter = payload;
  },
  setNewsCate:(state,payload) => {
    state.newsCate = payload;
    state.firstCateId = state.newsCate[0]._id;
  },
}

const actions = {
  setFilter:({commit},payload)=>{
    commit("setFilter",payload)
  },
  setNewsCate:({commit},payload)=>{
    Vue.axios.get(`http://localhost:3000/cate/list/${payload}`)
    .then(res => {
      commit("setNewsCate",res.data)
    })
  },
}

export default {
  state,
  getters,
  mutations,
  actions
}
